package com.zb.sannuo.thereport.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zb.sannuo.common.domain.ReportList;
import com.zb.sannuo.common.domain.search.DrugstoreInfo;
import com.zb.sannuo.common.domain.vo.ReportVo;
import com.zb.sannuo.common.result.Result;
import com.zb.sannuo.common.result.ResultCode;
import com.zb.sannuo.thereport.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/reports")
@Api(tags = "报表管理模块",description = "对报表管理进行CRUD操作")
@CrossOrigin
public class ReportController {

    @Resource
    private ReportService reportServiceImpl;

    @ApiOperation(value = "根据条件查询检测指标信息且分页操作",notes = "根据条件查询检测指标信息且分页操作",httpMethod = "GET")
    @RequestMapping(value = "findZb",method = RequestMethod.GET)
    public Result findZb(Integer page, Integer limit, String searchParams) throws Exception {

        ObjectMapper mapper = new ObjectMapper();
        ReportVo reportVo = null;
        if (searchParams != null && !"".equals(searchParams)){
            reportVo = mapper.readValue(searchParams, ReportVo.class);
        }
        Page jcZbPage = reportServiceImpl.JcZbPage(page, limit, reportVo);
        return Result.ok(ResultCode.SUCCESS,jcZbPage.getTotal(),jcZbPage.getRecords());
    }

    @ApiOperation(value = "根据条件查询检测记录且分页操作",notes = "根据条件查询检测记录且分页操作",httpMethod = "GET")
    @RequestMapping(value = "findR",method = RequestMethod.GET)
    public Result findJcRecord(Integer page, Integer limit, String searchParams) throws Exception{

        ObjectMapper mapper = new ObjectMapper();
        ReportVo reportVo = null;
        if (searchParams != null && !"".equals(searchParams)){
            reportVo = mapper.readValue(searchParams, ReportVo.class);
        }
        Page listPage = reportServiceImpl.RecordPage(page, limit, reportVo);
        System.out.println(listPage);
        return Result.ok(ResultCode.SUCCESS,listPage.getTotal(),listPage.getRecords());
    }

    @RequestMapping(value = "findZdName",method = RequestMethod.GET)
    public Result findZbName() throws Exception {
        List<DrugstoreInfo> zdName = reportServiceImpl.queryZdName();
        return Result.ok(ResultCode.SUCCESS,zdName);
    }

    @RequestMapping(value = "findFdName",method = RequestMethod.GET)
    public Result findFdName(String headStoreCode) throws Exception {
        List<DrugstoreInfo> fdName = reportServiceImpl.queryFdName(headStoreCode);
        return Result.ok(ResultCode.SUCCESS,fdName);
    }

    @RequestMapping(value = "findZbName",method = RequestMethod.GET)
    public Result queryZbName() throws Exception {
        List<ReportList> zbName = reportServiceImpl.queryZbName();
        return Result.ok(ResultCode.SUCCESS,zbName);
    }
}
